mod districts;

pub fn get_province(code: &str) -> Option<&'static str> {
    let idx = districts::DISTRICTS
        .binary_search_by(|(c, _)| c[..2].cmp(&code[..2]).then(c[2..6].cmp("0000")))
        .ok()?;
    Some(districts::DISTRICTS[idx].1)
}

pub fn get_city(code: &str) -> Option<&'static str> {
    let idx = districts::DISTRICTS
        .binary_search_by(|(c, _)| c[..4].cmp(&code[..4]).then(c[4..6].cmp("00")))
        .ok()?;
    Some(districts::DISTRICTS[idx].1)
}

pub fn get_district(code: &str) -> Option<&'static str> {
    let idx = districts::DISTRICTS
        .binary_search_by_key(&&code[..6], |(code, _)| code)
        .ok()?;
    Some(districts::DISTRICTS[idx].1)
}
